package demo.MethodStaticReference;

import java.util.Arrays;

public class Test {
    public static void main( String[] args ) {
        // 静态方法引用
        test1();
        // 实例方法引用
        test2();
    }

    public static void test1() {
        Student[] students = new Student[3];
        students[0] = new Student("张三", 19, 170.0, '男');
        students[1] = new Student("李四", 21, 160.0, '女');
        students[2] = new Student("王五", 18, 180.0, '男');

        // 按年龄升序
        // 静态方法引用简化
        Arrays.sort(students, Student::compareByAge);

        for ( int i = 0; i < students.length; i++ ) {
            Student student = students[i];
            System.out.println(student);
        }

    }

    public static void test2() {
        Student[] students2 = new Student[3];
        students2[0] = new Student("张三", 19, 170.0, '男');
        students2[1] = new Student("李四", 21, 160.0, '女');
        students2[2] = new Student("王五", 18, 180.0, '男');

        // 按身高升序
        // 实例方法引用简化
        Student t = new Student();
        Arrays.sort(students2, t::compareByHeight);

        for ( int i = 0; i < students2.length; i++ ) {
            Student student = students2[i];
            System.out.println(student);
        }

    }


}
